package com.helen.adapter;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.helen.entity.AddressListEntity;
import com.helen.entity.MessageListEntity;
import com.helen.shopping.R;
import com.helen.ui.WebViewH5Activity;
import com.helen.utils.MyLog;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;

import java.util.List;


/**
 * Created by yang on 2017/11/23.
 */

public class MessageListAdapter extends BaseQuickAdapter<MessageListEntity, BaseViewHolder> {
    private OnSetItemDeleteListener onSetItemDeleteListener;

    public MessageListAdapter(int layoutResId, List<MessageListEntity> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final MessageListEntity item) {
        try {

            LinearLayout itemContent = (LinearLayout) helper.getView(R.id.ll_content);
            TextView tvTitle = (TextView) helper.getView(R.id.tv_title);
            TextView tvTime = (TextView) helper.getView(R.id.tv_time);
            TextView tvType = (TextView) helper.getView(R.id.tv_type);
            TextView tvDelete = (TextView) helper.getView(R.id.tv_delete);

            tvTitle.setText(item.getMsg());
            tvTime.setText(item.getTime());
            tvType.setText(item.getType());

            tvDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (onSetItemDeleteListener != null) {
                        onSetItemDeleteListener.setOnDeleteListener(item, helper.getLayoutPosition());
                    }
                }
            });


            itemContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent ti = new Intent(mContext, WebViewH5Activity.class);
                    ti.putExtra("id", item.getId());
                    mContext.startActivity(ti);
                }
            });


        } catch (Exception e) {
            MyLog.e("yang", "消息列表异常" + e.toString());
        }


    }


    public interface OnSetItemDeleteListener {
        void setOnDeleteListener(MessageListEntity messageListEntity, int position);
    }

    public void setOnItemDeleteListener(OnSetItemDeleteListener onItemDeleteListener) {
        this.onSetItemDeleteListener = onItemDeleteListener;
    }
}
